package com.example.javaee.controller;

import com.example.javaee.entity.Goods;
import com.example.javaee.entity.Order;
import com.example.javaee.entity.User;
import com.example.javaee.entity.UserOrder;
import com.example.javaee.service.GoodsService;
import com.example.javaee.service.UserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName BookController
 * @Description
 * @Author 杨理欢
 * @Date 2021/11/16 14:46
 * @Version V1.0
 */
@CrossOrigin
@Controller
public class UserOrderController {
    @Autowired
    UserOrderService userOrderService;

    @RequestMapping("findAllUserOrder")
    @ResponseBody
    public List<UserOrder> findAllUserOrder() {
        return userOrderService.findAllUserOrder();
    }

    @RequestMapping("findOrder")
    @ResponseBody
    public List<UserOrder> findOrder(int orderId) {
        System.out.println(orderId);
        return userOrderService.findOrder(orderId);
    }

    @RequestMapping("updateOrder")
    @ResponseBody
    public void updateOrder(@RequestBody Order order) {
        System.out.println(order);
        userOrderService.updateOrder(order);
    }

    @RequestMapping("updateUser")
    @ResponseBody
    public void updateUser(@RequestBody User user) {
        System.out.println(user);
        userOrderService.updateUser(user);
    }

    @RequestMapping("update")
    @ResponseBody
    public void update(User user, Order order) {
        updateOrder(order);
//        System.out.println(order);
        updateUser(user);
//        System.out.println(user);
    }
    @RequestMapping("deleteOrder")
    @ResponseBody
    public int deleteOrder(int orderId) {
        System.out.println(orderId);
        return userOrderService.deleteOrder(orderId);
    }
//待付款订单
    @RequestMapping("wxObligationOrder")
    @ResponseBody
    public List<Order> wxObligationOrder() {

        return userOrderService.wxObligationOrder();
    }
    //待发货订单

    @RequestMapping("wxToSendTheGoods")
    @ResponseBody
    public List<Order> wxToSendTheGoods() {

        return userOrderService.wxToSendTheGoods();
    }

    //待收货订单

    @RequestMapping("wxWaitForReceiving")
    @ResponseBody
    public List<Order> wxWaitForReceiving() {

        return userOrderService.wxWaitForReceiving();
    }

    @RequestMapping("updateOrderState")
    @ResponseBody
    public void updateOrderState(int orderId){

        userOrderService.updateOrderState(orderId);
    }
    //获取所有订单
    @RequestMapping("wxGetAllOrder")
    @ResponseBody
    public List<Order> wxGetAllOrder(){

      return  userOrderService.wxGetAllOrder();
    }
}
